#include<iostream>
#include<string>
#include<ctime>

using namespace std;

struct Hero
{
	string name;
	int age;
	string gender;
};

void SwapHero(Hero *hero1, Hero *hero2)
{
	Hero temp = *hero1;
	*hero1 = *hero2;
	*hero2 = temp;
}

void BubbleSort(Hero hArray[], int len)
{
	for (int i = 0; i < len - 1; i++)
	{
		for (int j = 0; j < len - i - 1; j++)
		{
			if (hArray[j].age > hArray[j + 1].age)
			{
				SwapHero(&hArray[j], &hArray[j + 1]);
			}
		}
	}
}

void PrintHero(Hero hArray[], int len)
{
	for (int i = 0; i < len; i++)
	{
		cout << hArray[i].name << " is a " << hArray[i].age << " years old " << hArray[i].gender << "." << endl;
	}
}

int main()
{
	Hero hArray[]=
	{
		{"Hero_A",32,"male"},
		{"Hero_B",43,"male"},
		{"Hero_C",21,"female"},
		{"Hero_D",56,"male"},
		{"Hero_E",13,"male"}
	};
	int len = sizeof(hArray) / sizeof(hArray[0]);

	PrintHero(hArray, len);
	cout << endl;
	BubbleSort(hArray, len);
	PrintHero(hArray, len);

	system("pause");

	return 0;
}